<html>
<head>
  <meta name="description" content="{home-description}">
  <meta name="keywords" content="{home-keywords}">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta property="og:title" content="{home-meta-title}">
  <meta property="og:description" content="{home-description}">
  <meta name="application-name" content="{home-meta-title}">
  <meta property="og:image" content="https://{home-netlify-domain}/{home-favicon}">
  <link rel="icon" type="image/png" href="https://{home-netlify-domain}/{home-favicon}">
  <title>{home-meta-title}</title>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap" rel="stylesheet">
  <script type="module" src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.esm.js"></script>
  <script nomodule src="ionicons.5.5.2.js"></script>
  <link rel="stylesheet" href="styles.css">
  <script src="isotope.3.0.6.pkgd.min.js"></script>
  <script src="jquery-3.6.1.min.js"></script>
  <script src="isMobile.js"></script>
</head>
<body>
  <div class="header-note"><b style="font-size: 30px; color: red">No longer maintained. Please visit <a href="https://beta.stremio-addons.net">beta.stremio-addons.net</a> for the new site.</b><div class="header-note-space"></div><b>Not all community addons are available in Stremio's internal addon catalog.</b><div class="header-note-space"></div>To load the community curated addons list in Stremio on your current device (presumes you have Stremio installed), simply press <a href="stremio://{home-netlify-domain}/catalog.json">this link</a>!</div>
  <h1>{home-page-title}</h1>
  <div id="searchBox" class="mobile-form">
      <form action="" class="search-form" id="searchform" method="get">
          <span id="noEasy">
               <input class="sb-search-submit" type="submit" value="">
               <ion-icon name="search"></ion-icon>
          </span>
          <input id="sbox" name="q" autocomplete="off" onblur="if (this.placeholder == '') {this.placeholder = 'Search addons';}" onfocus="this.value = ''; if (this.placeholder == 'Search addons') {this.placeholder = '';}" placeholder="Search addons" type="text" x-webkit-speech="">
      </form>
  </div>
  <div class="labels-list">{labels-list}</div>
  <div class="addon-list">{addons-list}</div>
  <div class="end-page-space"></div>
  <a class="addon-button footer-button" href="https://github.com/{repo-name}/blob/main/README.md#how-can-i-help" target="_blank">How Can I Help?</a><a class="addon-button footer-button" href="https://github.com/{repo-name}/blob/main/README.md#how-it-works" target="_blank">How It Works</a><a class="addon-button footer-button" href="https://github.com/{repo-name}/issues/new?assignees=&labels=pending+approval&template=submit-addon.yaml&title=Addon+Name" target="_blank">Publish Addon</a><a class="addon-button footer-button" href="https://github.com/{repo-name}/" target="_blank">Source Code</a><a class="addon-button footer-button" href="https://reddit.com/r/StremioAddons" target="_blank">Reddit</a><a class="addon-button footer-button" href="https://discord.gg/zNRf6YF" target="_blank">Discord</a><a class="addon-button footer-button" href="https://stremio.com/downloads" target="_blank">Download Stremio</a>
  <div class="end-page-space"></div>
  <div class="footer-note">Built with ❤️, the Stremio Addons website is curated by the community!</div>
  <script>
      let isotopeLoaded = false
      function loadIsotope() {
          isotopeLoaded = true
          window.iso = new Isotope('.addon-list', {
                itemSelector: '.addon-list-item',
                getSortData: {
                  bumps: itemElem => parseInt($(itemElem).find('.score-value').text()),
                  alpha: '.addon-title',
                },
                layoutMode: 'vertical',
                fitWidth: true
          })
          $('form#searchform').submit(function() {
              const query = $("input#sbox").val().toLowerCase()
              $("input#sbox").blur()
              $('.labels-list .label.selected').removeClass('selected')
              $($('.labels-list .label')[0]).addClass('selected')
              window.history.replaceState('', '', window.location.href.replace(window.location.search || '', '') + '?q=' + encodeURIComponent(query))
              window.iso.arrange({
                filter: function(itemElem) {
                  return $(itemElem).find('.addon-details .addon-title a').text().toLowerCase().includes(query)
                        || $(itemElem).find('.addon-details .addon-description').text().toLowerCase().includes(query)
                        || ($(itemElem).find('.addon-types .label-small').map((ij, el) => $(el).text()).toArray() || []).join(',').toLowerCase().includes(query)
                }
              })
              return false;
          })
          setTimeout(() => {
              const urlSearchParams = new URLSearchParams(window.location.search)
              const params = Object.fromEntries(urlSearchParams.entries())
              if (params.label) {
                  $('.labels-list .label.selected').removeClass('selected')
                  const pressedLabel = params.label.split('-').join(' ')
                  $('.labels-list .label').each(function() {
                      if ($(this).text() === pressedLabel)
                          $(this).addClass('selected')
                  })
                  const label = pressedLabel.split(' ').join('-')
                  window.iso.arrange({ filter: '.'+label })
              } else if (params.q) {
                  $("input#sbox").val(params.q)
                  const query = params.q.toLowerCase()
                  $("input#sbox").blur()
                  window.iso.arrange({
                    filter: function(itemElem) {
                      return $(itemElem).find('.addon-details .addon-title a').text().toLowerCase().includes(query)
                            || $(itemElem).find('.addon-details .addon-description').text().toLowerCase().includes(query)
                            || ($(itemElem).find('.addon-types .label-small').map((ij, el) => $(el).text()).toArray() || []).join(',').toLowerCase().includes(query)
                    }
                  })
              } else
                  window.iso.arrange({ sortBy: 'bumps', sortAscending: false })
          }, 250)
      }
      $(document).ready(function() {
          $('.labels-list .label').click(function() {
              if ($("input#sbox").val()) $("input#sbox").val('')
              $('.labels-list .label.selected').removeClass('selected')
              $(this).addClass('selected')
              const label = $(this).text().split(' ').join('-')
              window.history.replaceState('', '', window.location.href.replace(window.location.search || '', '') + (label === 'show-all' ? '' : '?label=' + label))
              window.iso.arrange({ filter: label === 'show-all' ? '*' : '.'+label })
          })
          $('.addon-types .label').click(function() {
              if ($("input#sbox").val()) $("input#sbox").val('')
              window.scrollTo(0, 0)
              $('.labels-list .label.selected').removeClass('selected')
              const pressedLabel = $(this).text()
              $('.labels-list .label').each(function() {
                  if ($(this).text() === pressedLabel)
                      $(this).addClass('selected')
              })
              const label = $(this).text().split(' ').join('-')
              window.history.replaceState('', '', window.location.href.replace(window.location.search || '', '') + '?label=' + label )
              window.iso.arrange({ filter: '.'+label })
          })
          loadIsotope()
      })
      function copyLink(event, link) {
        console.log('link', link);
        console.log('event', event);
    
        const copyLinkMsg = window.isMobile ? 'The link was copied to your clipboard.\nPress and hold in the search bar of the Stremio app, select Paste and press Enter.' : 'The link was copied to your clipboard.\nPress Ctrl + V in the search bar of the Stremio app and press Enter.';
        const promptMsg = window.isMobile ? 'Copy the link below by pressing and holding on it and selecting Copy.\nThen press and hold in the search bar of the Stremio app, select Paste and press Enter.' : 'Copy the link below by selecting it and pressing Ctrl + C.\nThen, Press Ctrl + V in the search bar of the Stremio app and press Enter.';
    
        navigator.clipboard.writeText(link).then(() => {
            console.log('Link copied to clipboard');
            window.alert(copyLinkMsg);
        }).catch(err => {
            console.error('Could not copy text: ', err);
            console.log('Fallback to prompt');
            window.prompt(promptMsg, link);
        });

        event.preventDefault();
        return false;
      }
  </script>
</body>
</html>
